package com.pikaqiu.warehouse.controller;

import com.pikaqiu.warehouse.domain.common.MiniAjaxResult;
import com.pikaqiu.warehouse.domain.dto.CompanyDto;
import com.pikaqiu.warehouse.domain.dto.CompanyIndexDto;
import com.pikaqiu.warehouse.domain.dto.HomeIndexDto;
import com.pikaqiu.warehouse.domain.req.CompanyForm;
import com.pikaqiu.warehouse.service.CompanyService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Administrator
 * @Date: 2024/8/15
 */
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Resource
    private CompanyService companyService;

    @GetMapping("/list")
    public MiniAjaxResult<List<CompanyDto>> listUserCompany() {
        return MiniAjaxResult.success(companyService.listUserCompany());
    }

    @GetMapping("/info")
    public MiniAjaxResult<CompanyIndexDto> info() {
        return MiniAjaxResult.success(companyService.info());
    }

    @GetMapping("/home/info")
    public MiniAjaxResult<HomeIndexDto> homeInfo() {
        return MiniAjaxResult.success(companyService.homeInfo());
    }

    @PostMapping("/change")
    public MiniAjaxResult<String> change(Integer id) {
        companyService.change(id);
        return MiniAjaxResult.success();
    }

    @PostMapping("/save")
    public MiniAjaxResult<String> saveCompany(CompanyForm companyForm) {
        companyService.saveCompany(companyForm);
        return MiniAjaxResult.success();
    }
}
